package cn.tlb.xutilsdownload.db;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 汤林冰 on 2015/11/27 14:27.
 */
public class MyDate {
    private Date date;

    private String dateString;

    public MyDate() {
    }

    public MyDate(Date date) {
        this.date = date;
    }

    public MyDate(String dateString) {
        parseString2Date(dateString);
    }

    //只支持"yyyy-MM-dd"匹配的字符串, 完全可以扩充方法以添加指定的pattern
    private void parseString2Date(String dateString) {
        this.dateString = dateString;
        try {
            date = new SimpleDateFormat("yyyy-MM-dd").parse(dateString);
        } catch (ParseException e) {
            new RuntimeException("only support \"yyyy-MM-dd\" format pattern!",e);
        }
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setDate(String dateString) {
        parseString2Date(dateString);
    }

    @Override
    public String toString() {
        return dateString;
    }
}
